#!/bin/sh

################################################################################
# modules_automatic
################################################################################
. /etc/rc.d/functions

start() {

    local file
    local file_old
    local file_new

    /usr/bin/logger -s -t minimyth -p "local0.info" "[init.d/modules_automatic] Starting..."

    mm_message_output info "loading kernel modules (automatic) ..."

    # Real time clock.
    /sbin/modprobe rtc
    # Setting max_usr_freq for rtc0 as it should be done after kernel rtc module is loaded...
    if [ -f /sys/class/rtc/rtc0/max_user_freq ] ; then
        /bin/echo 1024 > /sys/class/rtc/rtc0/max_user_freq
    fi
    if [ -f /proc/sys/dev/hpet/max-user-freq ] ; then
        /bin/echo 1024 > /proc/sys/dev/hpet/max-user-freq
    fi

    # IO scheduler.
    /sbin/modprobe as-iosched

    # Loopback device.
    /sbin/modprobe loop

    # Net.
    /sbin/modprobe af_packet

    # Parallel port.
    /sbin/modprobe parport
    /sbin/modprobe parport_pc
    /sbin/modprobe ppdev

    # uinput
    /sbin/modprobe uinput

    # generic scsi
    /sbin/modprobe sg

    # Enable modeprobe udev rules.
    /bin/mv -f /usr/lib/udev/rules.d/01-minimyth-modprobe.rules.disabled /usr/lib/udev/rules.d/01-minimyth-modprobe.rules

    # Trigger udev with the additional udev rules that handle detected hardware.
    /usr/bin/udevadm control --reload
    /usr/bin/udevadm trigger --action=add
    /usr/bin/udevadm settle --timeout=60

    /usr/bin/logger -s -t minimyth -p "local0.info" "[init.d/modules_automatic] Started with return code=0..."

    # Renabled by makefile subs.: hack for rpi kernel display reinit caussing splash black screen after modules load
    # mm_splash_init "loading kernel modules (automatic) ..."

    return 0
}

stop() {

    return 0
}

case $1 in
    start) start ;;
    stop)  stop  ;;
esac

exit 0
